"""
从商业IP代理获取代理服务器地址并保存到文件
"""
import json
import time

import requests

all_proxies = []
for _ in range(10):
    resp = requests.get(
        'http://piping.mogumiao.com/proxy/api/get_ip_bs?'
        'appKey=20c3b5de1fa14df7baeb608aa09971de&count=5&expiryDate=0&format=1&newLine=2'
    )
    data = resp.json()
    if data['code'] == '0':
        print(data['msg'])
        all_proxies += data['msg']
        time.sleep(11)
with open('proxy.json', 'w') as file:
    json.dump(all_proxies, file)
